      SUBROUTINE TCNVRT(YY,MM,DAORSC,TLAST,TIME,ITEST)
C
      IMPLICIT REAL*8 (A-H,O-Z)
      REAL*8 MM
C     SUBROUTINES REQUIRED: QTIME
C     IF ITEST=1 CONVERTS TIME FROM YEAR MONTH DAY AND DECIMAL PARTS TO
C           SECONDS FROM START OF THE YEAR, DAORSC=DAYS AND DEC.PARTS
C           OUTPUT IS TLAST WHICH IS SECONDS FROM START OF THE YEAR
C     IF ITEST=2 CONVERTS TIME IN SECONDS FROM START OF THE YEAR TO
C           YEAR MONTH DAY AND SECONDS,  DAORSC=SECONDS OF THE DAY
C           INPUT IS TIME WHICH IS SECONDS FROM START OF THE YEAR
C
      COMMON/IDATE1/ IY,IM,JWDAY
      COMMON/IMAIN1/ IDATE,LSAVE,INOPT,IPLOT,NUMEQS,IPLTPE,IORB,ITAPE
C
      DIMENSION JULDAY(12)
      DATA JULDAY /0,31,59,90,120,151,181,212,243,273,304,334/
C
      IY=IDATE/10000
      IF (ITEST .GE. 2)  GO TO 10
C
C     ********  COMPUTE TIME TO COMPARE WITH TIME ON ORBIT TAPE   ******
      NM=(IDATE-IY*10000)/100
      NDAY=MOD(IDATE,100)-1
C     **************  TEST FOR LEAP YEAR  ******************************
      IF(MOD(IY,4).EQ.0.AND.NM.GT.2) NDAY=NDAY+1
      KDAY=JULDAY(NM)+NDAY
      TIME=TIME+DFLOAT(KDAY)*8.64D4
C
      IM=MM
      LDAY=DAORSC-1.0
      SECOND=QTIME(DAORSC)
      NY=YY-1900.D0
C     **************  TEST FOR LEAP YEAR  ******************************
      IF(MOD(NY,4).EQ.0.AND.IM.GT.2) LDAY=LDAY+1
      JDAY=JULDAY(IM)+LDAY
      TLAST=DFLOAT(JDAY)*8.64D4+SECOND
      RETURN
   10 DAORSC=DMOD(TIME,8.64D4)
      MDAY=0
      IM=1
      IF (TIME .LE. 8.64D4)  DAORSC=TIME
C     JWDAY IS THE NUMBER OF WHOLE ELAPSED DAYS SINCE START OF YEAR
C     IDAY IS THE CALENDAR DAY OF THE MONTH
C     MDAY IS THE CALENDAR DAY OF THE MONTH MINUS 1
      JWDAY=(TIME-DAORSC)/8.64D4
      JDAY=JWDAY
      IF(JDAY.LE.0) GO TO 60
      IF (MOD(IY,4).EQ.0.AND.JDAY.GE.366) GO TO 55
      IF (MOD(IY,4).NE.0.AND.JDAY.GE.365) GO TO 50
   20 IF (MOD(IY,4) .EQ. 0  .AND.  JDAY .EQ. 59)  GO TO 40
      IF (MOD(IY,4) .EQ. 0  .AND.  JDAY .GT. 59)  JDAY=JDAY-1
      DO 30 I=1,11
      IF (JDAY.GE.JULDAY(I).AND.JDAY.LT.JULDAY(I+1)) GO TO 35
   30 CONTINUE
      IF (JDAY.GE.334.AND.JDAY.LT.365) I=12
   35 IM=I
      MDAY=JDAY-JULDAY(IM)
      MM=IM
      GO TO 60
   40 IM=2
      MDAY=28
      GO TO 60
   50 IY=IY+1
      JDAY=JDAY-365
      GO TO 20
   55 IY=IY+1
      JDAY=JDAY-366
      GO TO 20
   60 IDAY=MDAY+1
      KDATE=IDAY+IM*100+IY*10000
      YY=KDATE
      RETURN
      END
